package com.nowcoder.dao;

import com.nowcoder.model.News;
import javafx.scene.control.Tab;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface NewsDAO {
    String TABLE_NAME = "news";
    String INSET_FIELDS = " title,link,image,like_count,comment_count,created_date,user_id ";
    String SELECT_FIELDS = " id,title,link,image,like_count,comment_count,created_date,user_id ";

    @Insert({"insert into", TABLE_NAME, "(", INSET_FIELDS, ") values (#{title},#{link},#{image},#{likeCount},#{commentCount},#{createdDate},#{userId})"})
    int addNews(News news);

    @Select({"select", SELECT_FIELDS, "from", TABLE_NAME, "where id=#{id}"})
    News getById(int id);

    @Update({"update",TABLE_NAME,"set comment_count=#{commentCount} where id=#{id}"})
    int updateCommentCount(@Param("id") int id,@Param("commentCount") int commentCount);

    @Update({"update", TABLE_NAME,"set like_count=#{likeCount} where id=#{id}"})
    int updateLikeCount(@Param("id") int id,@Param("likeCount") int likeCount);

    List<News> selectByUserIdAndOffset(@Param("userId") int userId, @Param("offset") int offset, @Param("limit") int limit);
}
